//
//  RCMainController.swift
//  RC-微博0305
//
//  Created by 任淳 on 16/3/5.
//  Copyright © 2016年 ReverChun. All rights reserved.
//

import UIKit

class RCMainController: UITabBarController {

    func addBtnDidPush() {
        let composeVC = RCComposeController()
        let nav = UINavigationController(rootViewController: composeVC)
        //modal出nav
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        print(tabBar.classForCoder)
        let mainTabBar = RCMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        //添加按钮的点击方法
        mainTabBar.addBtn.addTarget(self, action: "addBtnDidPush", forControlEvents: .TouchUpInside)
        
        print(tabBar.classForCoder)
        
        //添加子控制器 (修改好tabBar类型之后再添加子控制器 要不然 新设置（重写）的tabBar不起作用)
        addChildViewControllers()
        
    }
    
    private func addChildViewControllers () {
        
        addViewController(RCHomeController(), title: "首页", imageName: "tabbar_home")
        addViewController(RCMessageController(), title: "消息", imageName: "tabbar_message_center")
        addViewController(RCDisController(), title: "发现", imageName: "tabbar_discover")
        addViewController(RCProController(), title: "我", imageName: "tabbar_profile")
        
    }
    

    private func addViewController(vc:UITableViewController ,title:String ,imageName:String) {
        
        let nav = UINavigationController(rootViewController: vc)
        UINavigationBar.appearance().tintColor = UIColor.purpleColor()
//        nav.navigationBar.tintColor = UIColor.orangeColor()
        //vc.title既设置了tabBar（下面）的文字 又设置nav(上面)的文字
        vc.title = title
        
        //设置vc的tabBarItem的图片和选中图片
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置tabBar里面 tabBarItem（图片和文字）的颜色
        tabBar.tintColor = UIColor.orangeColor()
        addChildViewController(nav)
        
    }
    
    

}
